package com.lin.sso.client01.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @作者: 林江
 * @创建时间: 2024/2/12
 * @功能:
 */
@Controller
@RequestMapping("client01")
public class Client01Controller {
    @Value("${sso.url}")
    public String url;

    @Autowired
    StringRedisTemplate redisTemplate;

    @RequestMapping("/boss")
    public String boss(Model model, @RequestParam(value = "token", required = false) String token) {
        if (StringUtils.isEmpty(token)) {
            return "redirect:" + url + "?" + "redirect=http://client01.sso.com:9001/client01/boss";
        }
        //判断是否具有权限访问，没有就跳到登录页
        String obj = redisTemplate.opsForValue().get(token);
        if (obj != null) {
            model.addAttribute("data", "boss");
            return "list";
        } else {
            return "redirect:" + url + "?" + "redirect=http://client01.sso.com:9002/client01/boss";
        }
    }
}
